﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using LSEntity;
using LSInterFace;
using LSUtility;

namespace LSBLL
{
    public class AuthorizeBase : AuthorizeAttribute
    {
        protected MemberEntity Member { get; set; }
        protected string Controller { get; set; }
        protected string Action { get; set; }
        protected bool IsLogin { get; set; }
        protected bool IsTeacher { get; set; }
        protected bool IsStudent { get; set; }

        protected void GetValue(AuthorizationContext filterContext)
        {
            Member = filterContext.HttpContext.Profile.MemberGetByProfile();
            IsLogin = false;
            IsTeacher = false;
            IsStudent = false;
            if (Member != null)
            {
                IsLogin = Member.AccountId > 0;
                IsTeacher = Member.Type == MemberTypeEntity.Teacher;
                IsStudent = Member.Type == MemberTypeEntity.Student;
            }
            Controller = filterContext.RouteData.Values["controller"].ToString();
            Action = filterContext.RouteData.Values["action"].ToString();
        }

        protected void GoUrl(string url)
        {
            HttpContext.Current.Response.Redirect(url);
        }
    }
}
